from flask import Blueprint
from flask_restful import Api, Resource
from models.news import user
from libs.response import generate_response
from libs.parse import user_parse

view01_bp = Blueprint('view01', __name__, url_prefix='/view01/')
api = Api(view01_bp)

class Users(Resource):
    def get(self):
        try:
            users = user.query.all()
            users = user_parse(users)
            return generate_response(data=users)
            # result = {
            #     "message": "OK",
            #     "status_code": 200,
            #     "data": users
            # }
            # return result
        except:
            result = {
                "status_code": 400,
                "message": "出错了"
            }
            return result

api.add_resource(Users, "/users/")

# @view01_bp.route('/index/')
# def index():
#     return "<h1>this is index<h1>"

# def index2():
#     return "<h1>this is index2<h1>"
# view01_bp.add_url_rule('/index2/', view_func=index2)